import { convertor, JavaType, PrecisionScale } from "./JavaTypeConvertor"

export const Convertor = {

    mysql: {
        char: convertor('char', JavaType.Character),
        varchar: convertor('varchar', JavaType.String),
        text: convertor('text', JavaType.String),
        int: convertor('int', JavaType.Integer, (db_type: string, java_type: string, precisionScale? : PrecisionScale)=>{
            if(precisionScale && precisionScale.precision && precisionScale.precision >11){
                return JavaType.Long
            } 
            return JavaType.Integer
        }),
        bigint: convertor('bigint', JavaType.Long),
        float: convertor('float', JavaType.Float),
        double: convertor('double', JavaType.Double),
        decimal: convertor('decimal', JavaType.BigDecimal),
        date: convertor('date', JavaType.Date),
        datetime: convertor('datetime', JavaType.Date),
        timestamp: convertor('timestamp', JavaType.Date),
        tinyint: convertor('tinyint', JavaType.Byte),
        blob: convertor('blob', JavaType.Blob),
    },
    postgres: {
        bit: convertor('bit', JavaType.Boolean),
        bool: convertor('bool', JavaType.Boolean),
        char: convertor('char', JavaType.Character),
        bpchar: convertor('bpchar', JavaType.String),
        varchar: convertor('varchar', JavaType.String),
        text: convertor('text', JavaType.String),
        int2: convertor('int2', JavaType.Integer),
        int4: convertor('int4', JavaType.Integer),
        int8: convertor('int8', JavaType.Long),
        float4: convertor('float4', JavaType.Float),
        float8: convertor('float8', JavaType.Double),
        numeric: convertor('numeric', JavaType.BigDecimal, (db_type: string, java_type: string, precisionScale? : PrecisionScale)=>{
            if(precisionScale && (!precisionScale.scale || precisionScale.scale == 0)){
                return JavaType.Long
            } 
            return JavaType.BigDecimal
        }),
        date: convertor('date', JavaType.Date),
        time: convertor('time', JavaType.Date),
        timestamp: convertor('timestamp', JavaType.Date),
        tinyint: convertor('tinyint', JavaType.Byte),
        blob: convertor('blob', JavaType.Blob),
    }
    
}